package com.sc.nft.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.controller.request.SubscribeProductDetailRequest;
import com.sc.nft.entity.vo.SubscribeProductDetailVo;
import com.sc.nft.entity.vo.SubscribeProductListVo;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.SubscribeProductService;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;

/**
*@author 刘国航
*@since 2024/5/16 17:50
*/
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/subscribeProduct")
@Api(tags ="申购记录")
public class SubscribeProductController {

    private final SubscribeProductService subscribeProductService;

    @ApiOperation(value = "列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<SubscribeProductListVo> list (@Valid @RequestBody PageRequest pageRequest) {
        return PageResult.success(subscribeProductService.list(UserPool.getUser(), pageRequest.toMp()));
    }

    @ApiOperation(value = "详情", notes = "详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/detail", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<SubscribeProductDetailVo> detail (@Valid @RequestBody SubscribeProductDetailRequest pageRequest) {
        return PageResult.success(subscribeProductService.detail(UserPool.getUser(), pageRequest.getProductId(), pageRequest.toMp()));
    }

}
